package com.hdax.dm.item.controller;

import com.hdax.dm.entity.item.ItemType;
import com.hdax.dm.item.dto.*;
import com.hdax.dm.item.service.ItemSearchService;
import com.hdax.dm.item.service.ItemService;
import com.hdax.dm.item.vo.ItemSearchVo;
import com.hdax.dm.utils.CommonResponse;
import com.hdax.dm.utils.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 商品搜索控制器
 */
@RestController
@RequestMapping(path = "/item")
public class ItemSearchController {

    @Autowired
    private ItemSearchService itemSearchService;

    @Autowired
    private ItemService itemService;

    /**
     * 根据params查询一、二级分类
     * @return
     */
    @ResponseBody
    @PostMapping(path = "list/sortgoods")
    public CommonResponse<List<ItemType>> sortgoods(@RequestBody Map<String,Long> param){
        List<ItemType> itemTypes = itemSearchService.itemTypes(param.get("param") == null ? 0 : param.get("param"));
        return ResponseUtil.returnSuccess(itemTypes);
    }

    /**
     * 查询城市列表信息
     */
    @ResponseBody
    @PostMapping(path = "list/querycity")
    public CommonResponse<List<AreaDto>> querycity(){
        return ResponseUtil.returnSuccess(itemSearchService.queryCities());
    }

    /**
     * 多条件搜索演出剧目（商品）
     * sort:
     * recommend:热门推荐
     * recentShow:最近开场
     * recentSell:最新上架
     */
    @ResponseBody
    @PostMapping(path = "list/querygoodsinfos")
    public CommonResponse<ItemSearchResultDto> querygoodsinfos(@RequestBody ItemSearchVo vo){
        try {
            return ResponseUtil.returnSuccess(itemSearchService.querygoodsinfos(vo));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * 今日推荐
     * @return
     */
    @ResponseBody
    @PostMapping(path = "index/recommend")
    public CommonResponse<List<HotItemDto>> recommend(){
        return ResponseUtil.returnSuccess(itemSearchService.recommend());
    }
    /**
     * 亲子精彩聚焦界面数据
     * @return
     */
    @ResponseBody
    @PostMapping(path = "paternity/recommend")
    public CommonResponse<List<HotItemDto>> recommendpaternity(){
        return ResponseUtil.returnSuccess(itemSearchService.recommends());
    }
    /**
     * 亲子猜你喜欢界面
     * @return
     */
    @ResponseBody
    @PostMapping(path = "paternity/guesslike")
    public CommonResponse<List<ItemsDto>> guesslikes(@RequestBody Map<String,Long> param){
        Long itemTypeId=param.get("itemTypeId");
        return ResponseUtil.returnSuccess(itemSearchService.guesslikes(itemTypeId));
    }
    /**
     * 亲子热门排行界面
     * @return
     */
    @ResponseBody
    @PostMapping(path = "paternity/guesslikeqs")
    public CommonResponse<List<ItemsDto>> guesslikeqs(@RequestBody Map<String,Long> param){
        Long itemTypeId=param.get("itemTypeId");
        return ResponseUtil.returnSuccess(itemSearchService.guesslikeqs(itemTypeId));
    }


    /**
     * 即将开售
     * @return
     */
    @ResponseBody
    @PostMapping(path = "index/sell")
    public CommonResponse<List<HotItemDto>> sell(){
        return ResponseUtil.returnSuccess(itemSearchService.sell());
    }

    /**
     * 猜你喜欢
     * @return
     */
    @ResponseBody
    @PostMapping(path = "list/guesslike")
    public CommonResponse<List<ItemsDto>> guesslike(@RequestBody Map<String,Long> param){
        Long itemTypeId=param.get("itemTypeId");
        return ResponseUtil.returnSuccess(itemSearchService.guesslike(itemTypeId));
    }

    /**
     * 楼层
     * @return
     */
    @ResponseBody
    @PostMapping(path = "index/floor")
    public CommonResponse<List<FloorDto>> floor(){
        return ResponseUtil.returnSuccess(itemSearchService.floor());
    }

    /**
     * 查询不同分类排行
     * @param map
     * @return
     */
    @RequestMapping("index/seniority")
    public CommonResponse seniority(@RequestBody Map<String,String> map){
        return ResponseUtil.returnSuccess(itemSearchService.seniority(map));
    }

    @RequestMapping("desc/getItems")
    public CommonResponse selectId(@RequestBody Map<String,String> param){
        Long id = Long.parseLong(param.get("id"));
        return ResponseUtil.returnSuccess(itemService.selectId(id));
    };
}
